/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * CadastroNivelTecnico.java
 *
 * Created on 20/11/2011, 15:15:19
 */
package telas;

import controle.NivelTecnicoControle;
import modelo.NivelTecnico;
import javax.swing.JOptionPane;

/**
 *
 * @author marahS2ddd
 */
public class CadastroNivelTecnico extends javax.swing.JFrame {

    private NivelTecnicoControle nivelTecnicoControle = new NivelTecnicoControle();
    /** Creates new form CadastroNivelTecnico */
    public CadastroNivelTecnico() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPCadastro = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jTFDescricao = new javax.swing.JTextField();
        jPBotoes = new javax.swing.JPanel();
        jButton2 = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Cadastrar Nível Técnico");
        setName("CadastroNivelTecnico"); // NOI18N
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jPCadastro.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jLabel1.setText("Descrição:");
        jPCadastro.add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 20, 90, 20));

        jTFDescricao.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTFDescricaoActionPerformed(evt);
            }
        });
        jPCadastro.add(jTFDescricao, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 40, 200, -1));

        getContentPane().add(jPCadastro, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 10, 470, 120));

        jPBotoes.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagem/Salvar.png"))); // NOI18N
        jButton2.setText("Salvar");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });
        jPBotoes.add(jButton2, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 30, 130, 40));

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagem/cancelar.gif"))); // NOI18N
        jButton1.setText("Cancelar");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        jPBotoes.add(jButton1, new org.netbeans.lib.awtextra.AbsoluteConstraints(280, 30, 130, 40));

        getContentPane().add(jPBotoes, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 140, 450, 100));

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jTFDescricaoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTFDescricaoActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTFDescricaoActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        // inserir Nivel Técnico
        
        try{
            
            NivelTecnico nivelTecnico = new NivelTecnico();
            
            // Setando os valores dos campos nos atributos do objeto
            nivelTecnico.setDescricao(jTFDescricao.getText());
            
            NivelTecnicoControle nivelTecnicoControle = new NivelTecnicoControle(nivelTecnico);
            
            nivelTecnicoControle.inserir();
            
            JOptionPane.showMessageDialog(this, "Registro inserido com sucesso!");
            jTFDescricao.setText(null);
            
            jTFDescricao.grabFocus();
                      
        }catch (RuntimeException e) {
            JOptionPane.showMessageDialog(this, "Não foi possível ao inserir registro."+e.getMessage(),"Erro",JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        dispose();
    }//GEN-LAST:event_jButton1ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new CadastroNivelTecnico().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPBotoes;
    private javax.swing.JPanel jPCadastro;
    private javax.swing.JTextField jTFDescricao;
    // End of variables declaration//GEN-END:variables
}
